package com.multitrack.map.datatype;

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;

/*
 * 클래스: Marker
 * 작성자: BBJ
 * 작성일: 2012. 09. 26
 * 수정자:
 * 수정일:
 * 코멘트:
 */

public class Marker {

	protected Drawable drawable;
	protected OverlayItem item;
	protected ItemizedOverlays overlays;
	protected CustomMapView mapView;

	public Marker(CustomMapView mapView, Context context, int id) {
		this.mapView = mapView;
		this.drawable = context.getResources().getDrawable(id);
		this.overlays = new ItemizedOverlays(drawable, context);
	}

	public Marker(CustomMapView mapView, Context context, Drawable drawable) {
		this.mapView = mapView;
		this.drawable = drawable;
		this.overlays = new ItemizedOverlays(drawable, context);
	}

	public void draw(GeoPoint point) {
		mapView.getOverlays().remove(overlays);
		overlays.remove(item);

		item = new OverlayItem(point, null, null);

		overlays.add(item);
		mapView.getOverlays().add(overlays);

		mapView.invalidate();
	}

	public void draw(GeoPoint point, String title, String snippet) {
		mapView.getOverlays().remove(overlays);
		overlays.remove(item);

		item = new OverlayItem(point, title, snippet);

		overlays.add(item);
		mapView.getOverlays().add(overlays);

		mapView.invalidate();
	}

	public void addDraw(GeoPoint point, String title, String snippet) {
		mapView.getOverlays().remove(overlays);

		item = new OverlayItem(point, title, snippet);
		overlays.add(item);
		mapView.getOverlays().add(overlays);

		mapView.invalidate();
	}

	public void clear() {
		mapView.getOverlays().remove(overlays);
		overlays.remove(item);

		mapView.invalidate();
	}

	public void add(OverlayItem item) {
		overlays.add(item);
	}
	
	public void remove(OverlayItem item) {
		overlays.remove(item);
	}

	public ItemizedOverlays getOverlays() {
		return overlays;
	}

	public void setOverlays(ItemizedOverlays overlays) {
		this.overlays = overlays;
	}

	public OverlayItem getItem() {
		return item;
	}

	public void setItem(OverlayItem item) {
		this.item = item;
	}

	public Drawable getDrawable() {
		return drawable;
	}

	public void setDrawable(Drawable drawable) {
		this.drawable = drawable;
	}

	public void setDrawable(Context context, int id) {
		this.drawable = context.getResources().getDrawable(id);
	}
}
